#include <stdio.h>
#include <stdlib.h>
#include <tf_mm_alloc.h>
#include <tf_xm.h>
#include <tf_mem.h>
#include <tf_mm_cons.h>
#include <omp.h>

int main(int argc, char ** argv) {
	omp_set_num_threads(2);
#pragma omp parallel 
{
	printf("Setting memory : (%d)\n", omp_get_thread_num() );
	tf_mem_set_size(4096);
	printf("TF_init calling... (%d)\n", omp_get_thread_num() );
	tf_init();

	printf("Using TF_XM_START (%d)\n", omp_get_thread_num() );
	tf_xm_start(argc, argv);

	void* glob = tf_mem_get_address();
	//Compete for a ressource :
	for ( int i = 0; i < 1000;++i) {
	    tf_mm_cons_exclusive_acquire( glob+20, 10);
  	    tf_mm_cons_release( glob+20 );
	    tf_mm_cons_exclusive_acquire( glob+30, 10);
  	    tf_mm_cons_release( glob+30 );
	}
	
	printf("Hello, from %d\n", dfrt_whoami());
	sleep(1);
}

}


